home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 19
/
CD_ASCQ_19_010295.iso
/
dos
/
prg
/
pas
/
swag
/
math.swg
/
0030_More Primes Yet !!.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-08-27
|
754b
|
33 lines
{
JANOS SZAMOSFALVI
the following routine uses a brute force approach with some
optimization; it took less than 3 minutes with a 286/12 to find
and print all primes up to 32768, about 50 seconds w/o printing
them; it becomes a bit slow when you get into a 6 digit range
}
PROGRAM Primes;
VAR
number,
max_div,
divisor : INTEGER;
prime : BOOLEAN;
BEGIN
writeln('Primes:');
writeln('2');
FOR number := 2 TO MAXINT DO
BEGIN
max_div := Round(sqrt(number) + 0.5);
prime := number MOD 2 <> 0;
divisor := 3;
WHILE prime AND (divisor < max_div) DO
BEGIN
prime := number MOD divisor <> 0;
divisor := divisor + 2;
END;
IF prime THEN
writeln(number);
END;
END.